import Vue from "vue";
import App from "./App";
import store from "./store";

// 时间格式化过滤器
Vue.filter("formatDate", (originVal, format) => {
    if (typeof originVal === "string") {
        var mts = originVal.match(/(\/Date\((\d+)\)\/)/);
        if (mts && mts.length >= 3) {
            originVal = parseInt(mts[2]);
        }
    }
    originVal = new Date(originVal);
    if (!originVal || originVal.toUTCString() == "Incalid Date") {
        return "";
    }

    var map = {
        M: originVal.getMonth() + 1, //月份
        d: originVal.getDate(), //日
        h: originVal.getHours(), //时
        m: originVal.getMinutes(), //分
        s: originVal.getSeconds(), //秒
        q: Math.floor((originVal.getMonth() + 3) / 3), //季度
        S: originVal.getMilliseconds(), //毫秒
    };

    format = format.replace(/([yMdhmsqS])+/g, function(all, t) {
        var v = map[t];
        if (v != undefined) {
            if (all.length > 1) {
                v = "0" + v;
                v = v.substr(v.length - 2);
            }
            return v;
        } else if (t === "y") {
            return (originVal.getFullYear() + "").substr(4 - all.length);
        }
        return all;
    });
    return format;
});

// 定义成全局组件
Vue.prototype.$store = store;

Vue.config.productionTip = false;

App.mpType = "app";

const app = new Vue({
    // 挂载
    ...App,
    store,
});
app.$mount();